/*
* Graph.h
*
*  Created on: Mar 8, 2017
*      Author: along
*/

#ifndef GRAPH_H_
#define GRAPH_H_

#include "my_io.h"
#include <vector>
#include <map>

using namespace std;

struct Edge {
	int from, to, cap, flow, cost,next;
	Edge()
	{
		from=to=cap=flow=cost=next=-1;
	}
	Edge(int from_t, int to_t, int cap_t, int cost_t)
	{
		from = from_t;
		to = to_t;
		cap = cap_t;
		cost = cost_t;
		flow = 0;
		next = -1;
	}
};

struct Consumer
{
    int id,network_node,id_g,need;
    Consumer(){}
    Consumer(int id_t,int network_node_t,int id_g_t,int need_t)
    {
        id = id_t;
        network_node = network_node_t;
        id_g = id_g_t;
        need = need_t;
    }
};

struct NetworkNode
{
	int id,flow,cost;
	NetworkNode(){}
	NetworkNode(int id_t,int flow_t,int cost_t )
	{
		id = id_t;
		flow = flow_t;
		cost = cost_t;
	}
	bool operator <(NetworkNode b) const
	{
		return b.cost/b.flow > cost/flow;
	}
};


class Graph {
private:
	vector<map<int, Edge> > g;
	int size_g;
public:
	Graph(){}
	Graph(int size)
	{
		g.resize(size);
		size_g = size;
	}
	int size()
	{
		return size_g;
	}
	void insert_edge(Edge e)
	{
		g[e.from][e.to] = e;
	}
	Edge get_edge(int from, int to)
	{
		return g[from][to];
	}
	vector<Edge> get_edges(int from)
	{
		vector<Edge> ret;
		for (map<int, Edge>::iterator it = g[from].begin(); it != g[from].end(); it++)
		{
			ret.push_back(it->second);
		}
		return ret;
	}
	vector<Edge> get_all_edges()
	{
		vector<Edge> ret;
		for (int i = 0; i < size_g; i++)
		{
			for (map<int, Edge>::iterator it = g[i].begin(); it != g[i].end(); it++)
			{
				ret.push_back(it->second);
			}
		}
		return ret;
	}
};

#endif /* GRAPH_H_ */
